package cake.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cake.dao.CakeImgDao;
import cake.dao.impl.CakeDaoImpl;
import cake.dao.impl.CakeImgDaoImpl;
import cake.entity.Cake;
import cake.entity.CakeImg;
@WebServlet("/admin/AddCakeImg.html")
public class AdminCakeImgServlet extends HttpServlet {
	private CakeDaoImpl cakeDaoImpl = new CakeDaoImpl();
	private CakeImgDao cakeImgDao = new CakeImgDaoImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int cid=0;
		if(request.getParameter("cid")!=null && !request.getParameter("cid").isEmpty()) {
			cid=Integer.parseInt(request.getParameter("cid"));
			Cake cake = cakeDaoImpl.getCakeById(cid);
			request.setAttribute("cakeName",cake.getName());
			request.setAttribute("kid", cid);
		}
		Cake cake = cakeDaoImpl.getCakeById(cid);
	    request.setAttribute("cakeName",cake.getName());
		List<CakeImg> cakeImgs = cakeImgDao.getImgByCid(cid);
		request.setAttribute("cakeImgs", cakeImgs);
		request.getRequestDispatcher("AddCakeImg.jsp").forward(request, response);
	}
}
